<?php

class Cities_Table_Populator {

    public $estate_name;
    public $cities;
    
    public $cities_table_name;
    public $estate_name_column_name;
    public $city_name_column_name;
    
    public function __construct($cities_table_name, $estate_name_column_name, $city_name_column_name) {
        $this->cities_table_name = $cities_table_name;
        $this->estate_name_column_name = $estate_name_column_name;
        $this->city_name_column_name = $city_name_column_name;
    }
    
    public function populate_cities_table($connection) {
        foreach($this->cities as $city) {
            $city = trim(str_ireplace('*', '', $city));
            $sql_city = "INSERT INTO {$this->cities_table_name}({$this->estate_name_column_name},
                {$this->city_name_column_name}) VALUES('{$this->estate_name}', '{$city}')";
            mysql_query($sql_city, $connection);
        }
        return count($cities);
    }

}

?>
